import 'package:easy_chat_app/commons/widget/UserHeadPortrait.dart';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';

class UserHeadPortraitInfo {
  String? code;

  String? headPortrait;

  String? headPortraitStoreType;

  UserHeadPortraitInfo.create(
      this.code, this.headPortrait, this.headPortraitStoreType);
}

class ChatGroupHeadPortrait {
  static final Logger logger = Logger();

  static Widget create(
      List<UserHeadPortraitInfo> userHeadPortraitInfoList, double size,
      {double circularRadius = 2}) {
    int userCount = userHeadPortraitInfoList.length;
    if (userCount == 0) {
      return FlutterLogo(
        size: size,
      );
    }
    if (userCount <= 4) {
      double subHeadPortraitSize = size / 2 - 2;
      return Center(
        child: SizedBox(
          width: size,
          height: size,
          child: GridView.count(
            crossAxisCount: 2,
            physics: const NeverScrollableScrollPhysics(),
            children: List.generate(userHeadPortraitInfoList.length, (index) {
              var item = userHeadPortraitInfoList[index];
              return UserHeadPortrait.network(
                  size: subHeadPortraitSize,
                  userCode: item.code!,
                  userHeadPortrait: item.headPortrait!,
                  userHeadPortraitStoreType: item.headPortraitStoreType!,
                  circularRadius: circularRadius);
            }),
          ),
        ),
      );
    } else {
      double subHeadPortraitSize = size / 3 - 2;
      int length = userHeadPortraitInfoList.length;
      if (length > 9) {
        length = 9;
      }
      return Center(
        child: SizedBox(
          width: size,
          height: size,
          child: GridView.count(
            physics: const NeverScrollableScrollPhysics(),
            crossAxisCount: 3,
            children: List.generate(userHeadPortraitInfoList.length, (index) {
              var item = userHeadPortraitInfoList[index];
              return UserHeadPortrait.network(
                  size: subHeadPortraitSize,
                  userCode: item.code!,
                  userHeadPortrait: item.headPortrait!,
                  userHeadPortraitStoreType: item.headPortraitStoreType!,
                  circularRadius: circularRadius);
            }),
          ),
        ),
      );
    }
  }
}
